package dragon.simpleOAuth.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class BeanFactory {
    /**
     * 密码加密器
     * @return
     */
    @Bean
    PasswordEncoder passwordEncoder() {
        /* 返回的encoder实现类实际上是 DelegatingPasswordEncoder , 它其实是一个 PasswordEncoder 代理,
        代理了其他一组 PasswordEncoder
        DelegatingPasswordEncoder 用于密码匹配的密码密文必须符合格式 : "{encoderId}xxxxxxx",
        它所代理的某个 PasswordEncoder 所能接收的密码密文应该是上面例子密码中的 "xxxxxxx" 部分
        看源码就会知道，默认返回BCryptPasswordEncoder
         */
        return PasswordEncoderFactories.createDelegatingPasswordEncoder();
    }
}
